package xmlS
{
	import main.XMLLoaderBase;
	
	public class TrafficXMLLoader extends XMLLoaderBase
	{
		private var _callBack:Function;
		private var _data:Object = {};
		public function TrafficXMLLoader()
		{
			super();
		}
		
		public function get dataList():Object
		{
			return _data;
		}
		
		public function init(callBack:Function = null):void
		{
			_callBack = callBack;
			super.loadXml(uri.getEatingResturantXmlUri("traffic"),loadXMLComplete);
		}
		
		private function loadXMLComplete(value:XML):void
		{
			var xml:XMLList = value.child("long");
			_data.longTip = String(xml.child("tip"));
			xml = xml.child("item");
			
			var dataList:Array = [];
			for(var i:int=0;i<xml.length();i++)
			{
			var info:Object = {};
				info.start = String(xml[i].@start);
				info.end = String(xml[i].@end);
				info.time = String(xml[i].@time);
				dataList.push(info);
			}
			
			_data.longList = dataList;
			
			xml = value.child("sea");
			_data.seaTip = String(xml);
			
			var shortList:Array = [];
			xml = value.child("short");
			_data.shortTip = String(xml.child("tip"));
			xml = xml.child("group");
			for(i = 0;i<xml.length();i++)
			{
				var sInfo:Object = {};
				sInfo.name = String(xml[i].@name);
				var xmlItem:XMLList = xml[i].child("item");
			    sInfo.start = String(xmlItem[0].@start);
				sInfo.end = String(xmlItem[0].@end);
				sInfo.startTime = String(xmlItem[0].@time);
				if(xmlItem[1])
				{
					sInfo.endTime = String(xmlItem[1].@time);
				}else
				{
					sInfo.endTime = "";
				}
				shortList.push(sInfo);
			}
			_data.shortList = shortList;
			
			if(_callBack != null)
			{
				_callBack();
			}
		}
		
	}
}